package com.share.device.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.share.common.core.web.domain.AjaxResult;
import com.share.device.domain.Role;
import com.share.device.domain.Staff;
import com.share.device.domain.dto.StaffDto;
import com.share.device.service.AreaService;
import com.share.device.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private StaffService staffService;
    @Autowired
    private AreaService areaService;
    //人员分页列表
    @GetMapping("/getStaffList")
    public AjaxResult getStaffList(StaffDto staffDto){
        return AjaxResult.success(staffService.getStaffList(staffDto));
    }


    //角色下拉框
    @GetMapping("/getRoleList")
    public AjaxResult getRoleList(){
        return AjaxResult.success(staffService.getRoleList());
    }


    //区域下拉框
    @GetMapping("/getAreaListX")
    public AjaxResult getAreaListX(){
        return AjaxResult.success(areaService.list(new QueryWrapper<>()));
    }

    //新增人员
    @PostMapping("/addStaff")
    public AjaxResult addStaff(@RequestBody Staff staff){
        return AjaxResult.success(staffService.save(staff));
    }


    //删除人员
    @DeleteMapping("/deleteStaff/{id}")
    public AjaxResult deleteStaff(@PathVariable Integer id){
        return AjaxResult.success(staffService.removeById(id));
    }


    //查询人员详情
    @GetMapping("/queryStaff/{id}")
    public AjaxResult queryStaff(@PathVariable Integer id){
        return AjaxResult.success(staffService.getById(id));
    }

    //修改人员
    @PutMapping("/updateStaff")
    public AjaxResult updateStaff(@RequestBody Staff staff){
        return AjaxResult.success(staffService.updateById(staff));
    }


}
